package com.cs.archivesmanagement.entity;

import javax.persistence.*;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

/**
 * Created by amo on 2015/8/24.
 */
@Entity
@Table(name = "am_archives_requests", schema = "", catalog = "csam")
public class AmArchivesRequests {


    public  static final Integer archivesRequestsStatus_pending=0;
    public  static  final Integer archivesRequestsStatus_approvaled=1;
    public  static  final Integer archivesRequestsStatus_denied=2;
    public  static  final Integer archivesRequestsStatus_rollback=3;



    public  static final Integer archivesRequestsType_add=0;
    public  static final Integer archivesRequestsType_delete=1;
    public  static final Integer archivesRequestsType_modify=2;
    public  static final Integer archivesRequestsType_get=3;



    private int archivesRequestsId;
    private Timestamp archivesRequestsArchiveEndTime;
    private Timestamp archivesRequestsArchiveTime;
    private Integer archivesRequestsStatus;
    private Integer archivesRequestsType;
    private AmAccount archivesRequestsArchiveApprovalUserId;
    private AmArchives archivesRequestsArchiveId;
    private AmAccount archivesRequestsUserId;

    public  AmArchivesRequests(Integer archivesRequestsId){
        this.archivesRequestsId=archivesRequestsId;
    }

  public AmArchivesRequests(){

      archivesRequestsStatus=archivesRequestsStatus_pending;
      archivesRequestsArchiveTime = new Timestamp(System.currentTimeMillis());

  }




    @Id
    @Column(name = "Archives_requests_id", nullable = false, insertable = true, updatable = true)
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    public int getArchivesRequestsId() {
        return archivesRequestsId;
    }

    public void setArchivesRequestsId(int archivesRequestsId) {
        this.archivesRequestsId = archivesRequestsId;
    }

    @Basic
    @Column(name = "Archives_requests_archive_end_time", nullable = true, insertable = true, updatable = true)
    public Timestamp getArchivesRequestsArchiveEndTime() {
        return archivesRequestsArchiveEndTime;
    }

    public void setArchivesRequestsArchiveEndTime(Timestamp archivesRequestsArchiveEndTime) {
        this.archivesRequestsArchiveEndTime = archivesRequestsArchiveEndTime;
    }

    @Basic
    @Column(name = "Archives_requests_archive_time", nullable = true, insertable = true, updatable = true)
    public Timestamp getArchivesRequestsArchiveTime() {
        return archivesRequestsArchiveTime;
    }

    public void setArchivesRequestsArchiveTime(Timestamp archivesRequestsArchiveTime) {
        this.archivesRequestsArchiveTime = archivesRequestsArchiveTime;
    }

    @Basic
    @Column(name = "Archives_requests_status", nullable = true, insertable = true, updatable = true)
    public Integer getArchivesRequestsStatus() {
        return archivesRequestsStatus;
    }

    public void setArchivesRequestsStatus(Integer archivesRequestsStatus) {
        this.archivesRequestsStatus = archivesRequestsStatus;
    }

    @Basic
    @Column(name = "Archives_requests_type", nullable = true, insertable = true, updatable = true)
    public Integer getArchivesRequestsType() {
        return archivesRequestsType;
    }

    public void setArchivesRequestsType(Integer archivesRequestsType) {
        this.archivesRequestsType = archivesRequestsType;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        AmArchivesRequests that = (AmArchivesRequests) o;

        if (archivesRequestsId != that.archivesRequestsId) return false;
        if (archivesRequestsArchiveEndTime != null ? !archivesRequestsArchiveEndTime.equals(that.archivesRequestsArchiveEndTime) : that.archivesRequestsArchiveEndTime != null)
            return false;
        if (archivesRequestsArchiveTime != null ? !archivesRequestsArchiveTime.equals(that.archivesRequestsArchiveTime) : that.archivesRequestsArchiveTime != null)
            return false;
        if (archivesRequestsStatus != null ? !archivesRequestsStatus.equals(that.archivesRequestsStatus) : that.archivesRequestsStatus != null)
            return false;
        if (archivesRequestsType != null ? !archivesRequestsType.equals(that.archivesRequestsType) : that.archivesRequestsType != null)
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = archivesRequestsId;
        result = 31 * result + (archivesRequestsArchiveEndTime != null ? archivesRequestsArchiveEndTime.hashCode() : 0);
        result = 31 * result + (archivesRequestsArchiveTime != null ? archivesRequestsArchiveTime.hashCode() : 0);
        result = 31 * result + (archivesRequestsStatus != null ? archivesRequestsStatus.hashCode() : 0);
        result = 31 * result + (archivesRequestsType != null ? archivesRequestsType.hashCode() : 0);
        return result;
    }

    @OneToOne
    @JoinColumn(name = "Archives_requests_archive_approval_user_id", referencedColumnName = "Account_id")
    public AmAccount getArchivesRequestsArchiveApprovalUserId() {
        return archivesRequestsArchiveApprovalUserId;
    }

    public void setArchivesRequestsArchiveApprovalUserId(AmAccount archivesRequestsArchiveApprovalUserId) {
        this.archivesRequestsArchiveApprovalUserId = archivesRequestsArchiveApprovalUserId;
    }

    @OneToOne
    @JoinColumn(name = "Archives_requests_archive_id", referencedColumnName = "Archives_id")
    public AmArchives getArchivesRequestsArchiveId() {
        return archivesRequestsArchiveId;
    }

    public void setArchivesRequestsArchiveId(AmArchives archivesRequestsArchiveId) {
        this.archivesRequestsArchiveId = archivesRequestsArchiveId;
    }

    @OneToOne
    @JoinColumn(name = "Archives_requests_user_id", referencedColumnName = "Account_id")
    public AmAccount getArchivesRequestsUserId() {
        return archivesRequestsUserId;
    }

    public void setArchivesRequestsUserId(AmAccount archivesRequestsUserId) {
        this.archivesRequestsUserId = archivesRequestsUserId;
    }


    public String startTimeString(){

        String tsStr = "";
        DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        try {
            //方法一
            tsStr = sdf.format(archivesRequestsArchiveTime);
         //   System.out.println(tsStr);
            //方法二
            //     tsStr = ts.toString();
            // System.out.println(tsStr);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return  tsStr;
    }


    public String endTimeString(){

        Timestamp ts = new Timestamp(System.currentTimeMillis());
        String tsStr = "";
        DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        try {
            //方法一
            tsStr = sdf.format(archivesRequestsArchiveEndTime);
          //  System.out.println(tsStr);
            //方法二
            //     tsStr = ts.toString();
            // System.out.println(tsStr);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return  tsStr;
    }

    public String statusString(){

        if(archivesRequestsStatus==archivesRequestsStatus_pending){

            return  "请求中";

        }

        else  if(archivesRequestsStatus==archivesRequestsStatus_denied){


            return "请求被拒绝";

        }

        else{


            return  "请求被批准";

        }



    }


    public String desString(){


       String  operationDes="";

        if(archivesRequestsType_add==archivesRequestsType)operationDes="增加";
        if(archivesRequestsType_modify==archivesRequestsType)operationDes="修改";
        if(archivesRequestsType_delete==archivesRequestsType)operationDes="删除";
        if(archivesRequestsType_get==archivesRequestsType)operationDes="借阅";

        return "申请了"+operationDes+getArchivesRequestsArchiveId().getArchivesTitle();


    }




}
